import { Button, Tooltip, Input, TreeSelect } from 'antd';
import { Fragment } from 'react';
import { PlusCircleOutlined, DeleteOutlined, AppstoreAddOutlined } from '@ant-design/icons';
import { stateOfRendering } from '../common';
import { history } from 'umi';
import { fieldFlowExport, getKeyRouter, getSelectDataMapList, getTenantID, priceFormat, removeDateHmsStr, renderTableText, tableSorter } from '@/utils';
import { formatDecimal, formatDecimalFour } from '../../Acommon';
import { ILoadMapTypeAll } from '@/common';

// Table表格的配置
const getTableColumn = (pageType, delSelectRow, openMaterialModalStatus, mapLoading, loadMapInfo) => {
  const assetAreaList = getSelectDataMapList(loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.ASSET_AREA}`], 'name', 'id', true);

  let tableConfig: Record<string, any>[] = [
    {
      title: '资产编号',
      dataIndex: 'assetCode',
      key: 'assetCode',
      width: 160,
      fixed: 'left',
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetCode'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '资产名称',
      dataIndex: 'assetName',
      key: 'assetName',
      width: 160,
      fixed: 'left',
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '资产分类',
      dataIndex: 'assetClassName',
      key: 'assetClassName',
      width: 120,
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetClassName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '品牌',
      dataIndex: 'brandType',
      key: 'brandType',
      width: 120,
      sorter: (a: any, b: any) => tableSorter(a, b, 'brandType'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '规格型号',
      dataIndex: 'paramsInfo',
      key: 'paramsInfo',
      width: 170,
      sorter: (a: any, b: any) => tableSorter(a, b, 'paramsInfo'),
      render: (text: string) => renderTableText(text, true),
    },
    // {
    //   title: '状态',
    //   dataIndex: 'assetStateName',
    //   key: 'assetStateName',
    //   width: 120,
    //   sorter: (a: any, b: any) => tableSorter(a, b, 'assetStateName'),
    //   render: (text: string) => renderTableText(text, true),
    // },
    // {
    //   title: '所属仓库',
    //   dataIndex: 'assetStoreName',
    //   key: 'assetStoreName',
    //   width: 150,
    //   sorter: (a: any, b: any) => tableSorter(a, b, 'assetStoreName'),
    //   render: (text: string) => renderTableText(text, true),
    // },
    {
      title: '数量',
      dataIndex: 'quantityOrArea',
      key: 'quantityOrArea',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'quantityOrArea'),
      render: (text: number | null) => formatDecimal(text),
    },
    {
      title: '计量单位',
      dataIndex: 'unitOfMeasurementName',
      key: 'unitOfMeasurementName',
      width: 140,
      sorter: (a: any, b: any) => tableSorter(a, b, 'unitOfMeasurementName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '资产原值（元）',
      dataIndex: 'totalValue',
      key: 'totalValue',
      width: 170,
      visible: true,
      sorter: (a: any, b: any) => (a.totalValue > b.totalValue ? 1 : -1),
      render: (text: number | null) => formatDecimalFour(text),
    },
    // {
    //   title: '管理部门',
    //   dataIndex: 'assetDepartmentName',
    //   key: 'assetDepartmentName',
    //   visible: true,
    //   width: 100,
    //   sorter: (a: any, b: any) => tableSorter(a, b, 'assetDepartmentName'),
    //   render: (text: string) => renderTableText(text, true),
    // },
    // {
    //   title: '使用人',
    //   dataIndex: 'asseterName',
    //   key: 'asseterName',
    //   visible: true,
    //   width: 90,
    //   sorter: (a: any, b: any) => tableSorter(a, b, 'asseterName'),
    //   render: (text: string) => renderTableText(text, true),
    // },
    {
      title: '使用部门',
      dataIndex: 'useDepartmentName',
      key: 'useDepartmentName',
      visible: true,
      width: 150,
      sorter: (a: any, b: any) => tableSorter(a, b, 'useDepartmentName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '使用人',
      dataIndex: 'userName',
      key: 'userName',
      visible: true,
      width: 150,
      sorter: (a: any, b: any) => tableSorter(a, b, 'userName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '存放区域',
      dataIndex: 'locationName',
      key: 'locationName',
      visible: true,
      width: 150,
      sorter: (a: any, b: any) => tableSorter(a, b, 'locationName'),
      // render: (text: string) => renderTableText(text, true),
      render: (text: string, record: Record<string, any>) => {
        return (
          <TreeSelect
            bordered={false}
            loading={mapLoading}
            placeholder="请选择"
            treeData={assetAreaList}
            fieldNames={{
              label: 'name',
              value: 'id',
              children: 'children',
            }}
            value={record?.location}
            style={{ width: '100%' }}
            showSearch={true}
            treeNodeFilterProp={'name'}
            allowClear={true}
            disabled={true}
          />
        );
      },
    },
    {
      title: '详细地点',
      dataIndex: 'locationInfo',
      key: 'locationInfo',
      visible: true,
      width: 180,
      sorter: (a: any, b: any) => tableSorter(a, b, 'locationInfo'),
      render: (text: string) => renderTableText(text, true),
    },
    // {
    //   title: '取得方式',
    //   dataIndex: 'obtainTypeName',
    //   key: 'obtainTypeName',
    //   visible: true,
    //   width: 100,
    //   sorter: (a: any, b: any) => tableSorter(a, b, 'obtainTypeName'),
    //   render: (text: string) => renderTableText(text, true),
    // },
    // {
    //   title: '取得日期',
    //   dataIndex: 'enterStoreTime',
    //   key: 'enterStoreTime',
    //   visible: true,
    //   width: 100,
    //   sorter: (a: any, b: any) => tableSorter(a, b, 'enterStoreTime'),
    //   render: (text: string) => removeDateHmsStr(text) || '--',
    // },
    // {
    //   title: '合同编号',
    //   dataIndex: 'contractCode',
    //   key: 'contractCode',
    //   visible: true,
    //   width: 100,
    //   sorter: (a: any, b: any) => tableSorter(a, b, 'contractCode'),
    //   render: (text: string) => renderTableText(text, true),
    // },
    // {
    //   title: '财务入账状态',
    //   dataIndex: 'entryStateName',
    //   key: 'entryStateName',
    //   visible: true,
    //   width: 100,
    //   sorter: (a: any, b: any) => tableSorter(a, b, 'entryStateName'),
    //   render: (text: string) => renderTableText(text, true),
    // },
  ];
  if (pageType != 'detail') {
    tableConfig?.push({
      title: (
        <div style={{ width: '100%', textAlign: 'center' }}>
          <Button
            type="link"
            disabled={pageType == 'detail'}
            size="small"
            onClick={openMaterialModalStatus}
            icon={<AppstoreAddOutlined />}
            className="manageBtntTxtStyle"
          >
            选择
          </Button>
        </div>
      ),
      dataIndex: 'operation',
      key: 'operation',
      width: 80,
      visible: true,
      unDrag: true,
      fixed: 'right',
      render: (_: string, record: Record<string, any>) => {
        return (
          <div className="counterpoartDelBtnStyle">
            <Button
              onClick={() => {
                delSelectRow(record);
              }}
              disabled={pageType == 'detail'}
              type={'link'}
              size={'small'}
              icon={<DeleteOutlined />}
              className={'manageBtntTxtStyle'}
            >
              删除
            </Button>
          </div>
        );
      },
    });
  }

  return tableConfig;
};

export { getTableColumn };
